//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tool.custom.progressbar;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.ProgressBar;

public class CProgressBar extends ProgressBar {
    int defaultColor = -16777216;
    String text;
    Paint mPaint;
    Context context;

    public CProgressBar(Context context) {
        super(context);
        this.context = context;
    }

    public CProgressBar(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public CProgressBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public synchronized void setProgress(int progress, String content) {
        this.text = content;
        super.setProgress(progress);
    }

    public synchronized void setProgress(int progress) {
        this.text = progress + "%";
        super.setProgress(progress);
    }

    protected synchronized void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(this.text != null) {
            this.initPaint();
            Rect rect = new Rect();
            this.mPaint.getTextBounds(this.text, 0, this.text.length(), rect);
            int x = this.getWidth() / 2 - rect.centerX();
            int y = this.getHeight() / 2 - rect.centerY();
            canvas.drawText(this.text, (float)x, (float)y, this.mPaint);
        }

    }

    private void initPaint() {
        this.mPaint = new Paint();
        this.mPaint.setColor(this.defaultColor);
        this.mPaint.setTypeface(Typeface.DEFAULT_BOLD);
        this.mPaint.setTextSize(20.0F);
        this.mPaint.setAntiAlias(true);
    }

    public int getDefaultColor() {
        return this.defaultColor;
    }

    public void setDefaultColor(int defaultColor) {
        this.defaultColor = defaultColor;
    }
}
